package com.falcon.controller.toolkit;

import com.falcon.mvc.base.IBaseController;
import com.falcon.mvc.domain.BaseResponse;
import com.falcon.domain.req.ControllerQuery;
import com.falcon.domain.req.DomainMetaQuery;
import com.falcon.domain.vo.ControllerMeta;
import com.falcon.domain.vo.DomainMeta;
import com.falcon.domain.vo.ServiceModuleVO;
import com.falcon.service.IControllerMetaService;
import com.falcon.service.IDomainMetaService;
import com.falcon.service.IModuleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author zongf
 * @since 2023-06-09
 **/
@RestController
@RequestMapping("/toolkit/project")
@Tag(name = "3.项目模块", description = "项目相关配置")
public class GenProjectController implements IBaseController {

    @Autowired
    private IModuleService moduleService;

    @Autowired
    private IControllerMetaService controllerMetaService;

    @Autowired
    private IDomainMetaService domainMetaService;

    @GetMapping("/java/serviceModuleList")
    @Operation(summary = "获取项目中所有 service 模块")
    public BaseResponse<List<ServiceModuleVO>> javaServiceModuleList() {

        List<ServiceModuleVO> moduleNames = this.moduleService.getServiceModuleNames();

        return BaseResponse.success(moduleNames);
    }

    @Operation(summary = "获取所有的 Controller")
    @PostMapping("/controller/list")
    public BaseResponse<List<ControllerMeta>> controllerList(@Valid @RequestBody ControllerQuery request) {
        List<ControllerMeta> list = this.controllerMetaService.getBaseControllers(request);
        return BaseResponse.success(list);
    }

    @Operation(summary = "获取所有的领域对象")
    @PostMapping("/domain/list")
    public BaseResponse<List<DomainMeta>> domainList(@Valid @RequestBody DomainMetaQuery request) {
        List<DomainMeta> list = this.domainMetaService.list(request);
        return BaseResponse.success(list);
    }

}
